import 'package:flutter/material.dart';

class SearchTextField extends StatelessWidget {
  String hintTextStr;
  Function onChange;

  SearchTextField({this.hintTextStr, this.onChange});

  Widget buildTextField() {
// theme设置局部主题

    return Theme(
        data: new ThemeData(primaryColor: Colors.grey),
        child: Container(
          padding: EdgeInsets.only(top: 5.0, left: 5.0),
          decoration: BoxDecoration(
              color: Colors.white,
              border: Border(
                bottom: BorderSide(width: 1.0, color: Colors.black12),
                top: BorderSide(width: 1.0, color: Colors.black12),
                right: BorderSide(width: 1.0, color: Colors.black12),
                left: BorderSide(width: 1.0, color: Colors.black12),
              )),
          child: TextField(
            cursorColor: Colors.grey, // 光标颜色

// 默认设置

            decoration: InputDecoration(
                contentPadding: const EdgeInsets.symmetric(vertical: 10.0),
                border: InputBorder.none,
                icon: Icon(Icons.search),
                hintText: hintTextStr,
                hintStyle: new TextStyle(
                    fontSize: 14, color: Color.fromARGB(50, 0, 0, 0))),

            style: new TextStyle(fontSize: 14, color: Colors.black),

            onChanged: onChange,
          ),
        ));
  }

  @override
  Widget build(BuildContext context) {
    return Container(
// 修饰搜索框, 白色背景与圆角
      decoration: new BoxDecoration(
        color: Colors.white,
        borderRadius: new BorderRadius.all(new Radius.circular(5.0)),
      ),

      alignment: Alignment.center,

      width: double.infinity,

      padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),

      child: buildTextField(),
    );
  }
}
